#ifndef __TIMER_H__
#define __TIMER_H__
#include "stdint.h"
#include "stdbool.h"
#include "string.h"

#define ms /8

typedef void (*timer_timeout_handler_t)(uint32_t context);
extern bool soft_timer_create(uint8_t *timer_id,uint8_t mode,timer_timeout_handler_t handler);
extern bool soft_timer_start(uint8_t timer_id,uint32_t ticks_to_expire,uint32_t context);
extern bool soft_timer_stop(uint8_t timer_id);
extern bool soft_timer_is_running(uint8_t timer_id);
extern bool soft_timer_init(void);
extern void soft_timer_updata(void);
extern int32_t get_tick(void);

typedef enum {
	MODE_ONE_SHOT,
	MODE_PERIODIC
}timer_mode_t;

typedef enum{
	SOFT_TIMER_STOPPED = 0,
	SOFT_TIMER_RUNNING,
	SOFT_TIMER_TIMEOUT,
	SOFT_TIMER_WAITING
}timer_state_t;


typedef struct{
	timer_timeout_handler_t handler;
	uint32_t ticks_to_expire;
	uint32_t ticks_to_period;
	uint32_t context;
	uint8_t  mode;
	uint8_t  state;	
}soft_timer_t;


#endif
